
// 1. 引入 定义user模块 的store
// 2. 创建实例

import { defineStore } from "pinia"

export const useUserStore = defineStore('user',{
    state(){
        return{
            msg:'hello pinia',
            user:"",
            tel: localStorage.getItem('tel')||'',
            count:10,
            userid: localStorage.getItem('userid')||''
        }
    },
    actions:{
        // 对state中数据 操作; 可以同步 也可以异步
        setTel(payload:any){
            this.tel = payload
            localStorage.setItem('tel',payload)
        },
        addCount(){
            this.count += 5
        },

        setUserId(payload:string){
            this.userid = payload
            localStorage.setItem('userid',payload)
        },        

    },
    getters:{
        doubleCount(){
            return this.count *2
        }
    }
})